aboutsummaryrefslogtreecommitdiff
path: root/src/routes/grocery/[id]/+page.server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/grocery/[id]/+page.server.ts')
-rw-r--r--src/routes/grocery/[id]/+page.server.ts9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/routes/grocery/[id]/+page.server.ts b/src/routes/grocery/[id]/+page.server.ts
index 6aed71e..d06c810 100644
--- a/src/routes/grocery/[id]/+page.server.ts
+++ b/src/routes/grocery/[id]/+page.server.ts
@@ -23,7 +23,7 @@ export interface GroceryDetailOutput {
categories: Category[];
}
-export const load: PageServerLoad = async ({ params }) => {
+export const load: PageServerLoad = async ({ params, url }) => {
const id = numericId(params.id);
const [item] = await db.select().from(groceries).where(eq(groceries.id, id));
@@ -38,6 +38,7 @@ export const load: PageServerLoad = async ({ params }) => {
const refs = await loadForGrocery(id);
const cats = await loadCategories();
+ const from = url.searchParams.get('from') || '/';
return {
item: {
@@ -46,6 +47,7 @@ export const load: PageServerLoad = async ({ params }) => {
},
references: refs,
categories: cats,
+ from,
};
};
@@ -95,7 +97,8 @@ export const actions: Actions = {
deleteItem: async ({ params, request }) => {
const groceryId = numericId(params.id);
await deleteGrocery(groceryId);
- const referer = request.headers.get('referer');
- throw redirect(303, referer || '/');
+ const data = await request.formData();
+ const from = parseFormString(data.get('from')) || '/';
+ throw redirect(303, from);
},
};